package com.itlong.cloud.controller.parking;

import com.itlong.cloud.POJO.DTO.operate.OperateFixedVehiclePageDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.project.property.IPropertyCarMonthCardServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      运营-智慧停车-固定车辆管理。
 * <desc/>
 *
 * @createDate 2018-11-05.
 */
@RestController
@RequestMapping("/parking/fixedVehicle")
public class OperateFixedVehicleController {

    private static final Logger LOG = LoggerFactory.getLogger(OperateFixedVehicleController.class);

    @Autowired
    private IPropertyCarMonthCardServiceClient iPropertyCarMonthCardServiceClient;

    /**
     * <desc>
     *      固定车辆信息分页查询
     * <desc/>
     *
     * @param operateFixedVehiclePageDTO 分页查询参数
     * @return
     * @author Qiang.S
     * @createDate 2018-11-05
     */
    @ResponseBody
    @AuthAccessRequired
    @RequestMapping(path = "/getFixedVehiclePage", method = RequestMethod.POST)
    public Object getFixedVehiclePage(OperateFixedVehiclePageDTO operateFixedVehiclePageDTO){
        MessageVO messageVO;
        try {
            HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            operateFixedVehiclePageDTO= HttpProtocolUtil.parseRequestParamToDTO(OperateFixedVehiclePageDTO.class,request);
            //请求对象不能为空
            if(null == operateFixedVehiclePageDTO){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),iPropertyCarMonthCardServiceClient.getFixedVehiclePage(operateFixedVehiclePageDTO));
        }catch (Exception e){
            throw new DataAccessException("【运营_智慧停车_固定车辆信息分页查询getFixedVehiclePage】固定车辆信息分页查询失败",e);
        }
        return messageVO;
    }

}
